   import { lazyReportBatch } from "../report";
   
   // 1. 定义上报数据的类型
    interface FetchReportData {
      type: 'performance';
      subType: 'fetch';
      url: string;
      pageUrl: string;
      startTime: number;
      endTime?: number;
      duration?: number;
      method?: string;
      status?: number;
      success?: boolean;
    }
    
    // 2. 保存原始 fetch
    const originalFetch = window.fetch;
    
    // 3. 重写 fetch
    function overwriteFetch() {
      window.fetch = function newFetch(input: RequestInfo | URL, config?: RequestInit): Promise<Response> {
        const startTime = Date.now();
    
        const reportData: FetchReportData = {
          type: 'performance',
          subType: 'fetch',
          url: typeof input === 'string' ? input : input instanceof URL ? input.toString() : input.url,
          pageUrl: window.location.href,
          startTime,
          method: config?.method,
        };
    
        return originalFetch(input, config)
          .then((res) => {
            const endTime = Date.now();
            reportData.endTime = endTime;
            reportData.duration = endTime - startTime;
            reportData.status = res.status;
            reportData.success = res.ok;
    
            // TODO: 上报 reportData
            console.log(reportData);
    
            return res;
          })
          .catch((err) => {
            const endTime = Date.now();
            reportData.endTime = endTime;
            reportData.duration = endTime - startTime;
            reportData.success = false;
            reportData.status = 0;
    
            // TODO: 上报 reportData
            console.error(reportData);
            //lazyReportBatch( reportData);
    
            throw err; // 必须抛出错误，不然 fetch 用户捕获不到
          });
      };
    }
    
    // 4. 初始化逻辑
    export default function fetchMonitor(): void {
      overwriteFetch();
    }